var token=localStorage.getItem("key");
	
//-1所有订单，0待付款，1待发货，2待收货，3待评价，4退款（4~7四个退款状态）
	
var statuList=[-1,0,1,2,3];
//开启loading。。。。。  $('#load').show();
choseOeder(statuList[0],0);
function choseOeder(type,num){
	if(num>statuList.length-1){
		//关闭loading。。。。。 $('#load').hide();
	}else{
		doGet(statuList[num],num);
	}
}

function doGet(type,num){
	$.ajax({
		type:"get",
		url:"/api/me/getMyOrders",
		async:true,
		data:{"token":token,"orderType": type},
		dataType:"json",
		success:function(data){
			choseOeder(statuList[++num],num);
			var list=data.data;
			var str="";
			if(list!='[]'&&list.length>0){
				for(var i = 0;i<list.length;i++){
					var goodsDetail=list[i].goods;
					if(goodsDetail.length&&goodsDetail.length>0){
						for(var j=0;j<goodsDetail.length;j++){
							if(list[i].status == "0"){
								str1 ='等待买家付款';
								str2 ='<span class="order" onclick="payNow(\''+list[i].orderId+'\')">立即付款</span>';
								str3 ='<div class="item-operation" style="cursor:pointer;" onclick="cancelOrder(\''+list[i].orderId+'\')">取消订单</div>';
							}else if(list[i].status == "1"){
								str1 = '买家已付款';
								str2 ='<span class="order">提醒发货</span>';
								str3 ='<div class="item-operation">退款</div>';
							}else if(list[i].status == "-1"){
								str1 = '交易关闭';
								str2 = '<div class="item-operation">删除</div>';
								str3 = '订单已取消'
							}else if(list[i].status == "2"){
								str1 = '卖家已发货<br/><a href="#">查看物流</a>';
								str2 ='<span class="order" onclick="confirmReceipt(\''+list[i].orderId+'\')">确认收货</span>';
								str3 ='<div class="item-operation">退款/退货</div>';
							}else if(list[i].status == "3"){
								str1 = '待评价';
								str2 ='<span class="order"><a href="../person/evaluate.html?id='+list[i].orderId+'&goodId='+goodsDetail[j].goodsId+'" style="color:#fff;">评价</a></span>';
								str3 ='<div class="item-operation">退款/退货</div>';
							}else if(list[i].status == "4"){
								str1 = '申请退货中';
							}else if(list[i].status == "5"){
								str1 = '商家同意退款';
							}else if(list[i].status == "6"){
								str1 = '商家拒绝退款';
							}else if(list[i].status == "7"){
								str1 = '收到退款';
							}else if(list[i].status == "8"){
								str1 = '已评价<br/>交易成功<br/><a href="#">查看物流</a>';
								str2 ='<span class="order">已评价</span>';
								str3 = '已评价';
							}
						    str+='<div class="order-title">'+
									'<div class="dd-num">订单编号：<a href="javascript:;">'+list[i].orderNo+'</a></div>'+
									'<span>成交时间：'+list[i].createTime+'</span>'+
								'</div>'+
								'<div class="order-content">'+
									'<div class="order-left">'+
										'<ul class="item-list">'+
											'<li class="td td-item">'+
												'<div class="item-pic">'+
													'<a href="../home/introduction.html?='+goodsDetail[j].goodsId+'" class="J_MakePoint">'+
														'<img src="'+goodsDetail[j].imgUrl+'" class="itempic J_ItemImg">'+
													'</a>'+
												'</div>'+
												'<div class="item-info">'+
													'<div class="item-basic-info">'+
														'<a href="../home/introduction.html?id='+goodsDetail[j].goodsId+'">'+
															'<p>'+goodsDetail[j].goodsName+'</p>'+
															'<p class="info-little">规格：'+goodsDetail[j].goodsStandard+
														'</a>'+
													'</div>'+
												'</div>'+
											'</li>'+
											'<li class="td td-price">'+
												'<div class="item-price">'+goodsDetail[j].goodsPrice+'</div>'+
											'</li>'+
											'<li class="td td-number">'+
												'<div class="item-number">'+
													'<span>×</span><span class="num">'+goodsDetail[j].num+'</span>'+
												'</div>'+
											'</li>'+
											'<li class="td td-operation">'+
												str3+
											'</li>'+
											'<li class="td td-amount">'+
												'<div class="item-amount">'+
													'<b>￥<span id="zj">'+Number(goodsDetail[j].goodsPrice*goodsDetail[j].num+Number(list[i].postage))+'</span></b>'+
													'<p>含运费：<span>￥'+list[i].postage+'</span></p>'+
												'</div>'+
											'</li>'+
											'<li class="td td-status">'+
												'<div class="item-status">'+
													'<p id="status">'+str1+'</p>'+
													'<p><a href="orderinfo.html?id='+list[i].orderId+'" target=_blank >订单详情</a></p>'+
												'</div>'+
											'</li>'+
											'<li class="td td-change">'+
												'<div class="am-btn am-btn-danger anniu">'+str2+'</div>'+
											'</li>'+
										'</ul>'+
									'</div>'+
								'</div>';
						}	
					}
					
				}
			}
			var mynum=num-1;
			console.log(mynum)
			$(".order-status"+(mynum==0?'':mynum)).html(str);	
		}
	});
}


//确认收货
function confirmReceipt(orderId){
	$.ajax({
		type:"get",
		url:"/api/me/confirmReceipt",
		async:true,
		data:{"token":token,"orderId":orderId},
		dataType:"json",
		success:function(data){
			console.log(data);
			window.location.reload();
		}
	});
}
//评价

function payNow(orderId){
	window.open("../home/lightpay.html?id="+orderId);
}
function cancelOrder(orderId){
	var isDel = window.confirm("确定取消订单？");
	if(isDel){
		$.ajax({
			type:"get",
			url:"/api/me/requestDeleteOrder",
			async:true,
			data:{"token":token,"orderId":orderId},
			dataType:"json",
			success:function(data){
				console.log(data);
			}
		});
		console.log(this);
		$(this).parents(".td-change").html("");
	}
	
}
